﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ControllerLayer.PatientInformation;

namespace ViewLayer.PatientInformationView
{
    public partial class PatientNoteViewControl : UserControl
    {

        public string patientOID;

        public PatientNoteViewControl(string patientOID)
        {
            this.patientOID = patientOID;
            InitializeComponent();

            try
            {
                this.staff_TableAdapter.Fill(this.externalPractitionerDataSet.Staff_);
                this.noteSeverityEnum_TableAdapter.Fill(this.externalPractitionerDataSet.NoteSeverityEnum_);

                this.patientNote_TableAdapter.Fill(this.patientNoteDataSet.PatientNote_, new System.Guid(patientOID));
                this.patientNoteCategory_TableAdapter.Fill(this.patientNoteDataSet.PatientNoteCategory_, new System.Guid(categoryOID_TextBox.Text));
            }
            catch (System.Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show(ex.Message); en caso que no exista una nota de paciente o la informacion
            }
        }

        private void patientNote_BindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();

            this.patientNoteCategory_BindingSource.EndEdit();
            this.patientNote_BindingSource.EndEdit();

            this.patientNoteCategory_TableAdapter.Update(this.patientNoteDataSet.PatientNoteCategory_);
           // this.patientNote_TableAdapter.Update(this.patientNoteDataSet.PatientNote_);

            authorOID_ComboBox.Enabled = false;
        }

        public void loadNoteCategory()
        {
            this.patientNoteCategory_TableAdapter.Fill(this.patientNoteDataSet.PatientNoteCategory_, new System.Guid(categoryOID_TextBox.Text));
        }

        private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
        {
            this.loadNoteCategory();
        }

        private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e)
        {
            this.loadNoteCategory();
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            this.patientNoteCategory_BindingSource.AddNew();

            PatientInformationViewController.FillFormForNewNote(this.patientOID, noteOID_TextBox, NoteVersion_TextBox, patientOID_TextBox, creationTime_DateTimePicker, CatOID_TextBox1, catVersion_TextBox1, authorOID_ComboBox, categoryOID_TextBox, deactivated_CheckBox);
        }

        private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
        {
            this.patientNoteCategory_BindingSource.CancelEdit();
            this.patientNote_BindingSource.CancelEdit();
        }
        

    }
}
